package com.bilibili.controller;

import com.bilibili.dto.VideoToJedis;
import com.bilibili.entity.BulletChat;
import com.bilibili.entity.Video;
import com.bilibili.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 获取视频的 controller接口
 */
@RestController
public class VideoController {
    @Autowired
    private VideoService videoService;

    /**
     * 用于主页面获取随机视频
     *
     * @return
     */
    @RequestMapping(value = "videos", method = RequestMethod.GET)
    public List<Video> getrandomvideos() {
        return videoService.getRandomVideo();
    }

    /**
     * 用于id获取指定视频
     *
     * @return
     */
    @RequestMapping(value = "videos/{id}", method = RequestMethod.GET)
    public Video getVideoById(@PathVariable("id") Integer id) {
        System.out.println(id);
        System.out.println(id);
        return videoService.getVideoById(id);
    }

    /**
     * 通过视频id获取对应的点击量等
     *
     * @return
     */
    @RequestMapping(value = "videos/{vid}", method = RequestMethod.GET, params = {"fetch_type=getvnumber"})
    public VideoToJedis getVideoToJedisByid(@PathVariable("vid") Integer vid) {
        return videoService.getVideoToJedisByid(vid);
    }

    /**
     * 通过视频id获取弹幕
     *
     * @return
     */
    @RequestMapping(value = "videos/{vid}", method = RequestMethod.GET, params = {"fetch_type=getbullet"})
    public List<BulletChat> getBulletChat(@PathVariable("vid") Integer vid) {
        return videoService.getBulletChatByid(vid);
    }

    /**
     * 添加弹幕
     *
     * @return
     */
    @RequestMapping(value = "videos", method = RequestMethod.POST)
    public boolean addBulletChat(@RequestBody BulletChat bulletChat) {
        System.out.println(bulletChat);
        return videoService.addBulletChat(bulletChat);
    }
}
